This function can lock the buffer for either reading or writing.
It may block if the hardware needs to finish rendering, if CPU caches
need to be synchronized, or possibly for other implementation-
specific reasons.
The passed AHardwareBuffer must have one layer, otherwise the call
will fail.
If \a fence is not negative, it specifies a fence file descriptor on
which to wait before locking the buffer. If it's negative, the caller
is responsible for ensuring that writes to the buffer have completed
before calling this function. Using this parameter is more efficient
than waiting on the fence and then calling this function.
The \a usage parameter may only specify AHARDWAREBUFFER_USAGE_CPU_*.
If set, then outVirtualAddress is filled with the address of the
buffer in virtual memory. The flags must also be compatible with
usage flags specified at buffer creation: if a read flag is passed,
the buffer must have been created with
AHARDWAREBUFFER_USAGE_CPU_READ_RARELY or
AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN. If a write flag is passed, it
must have been created with AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY or
AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN.
If \a rect is not NUL, the caller promises to modify only data in
the area specified by rect. If rect is NUL, the caller may modify
the contents of the entire buffer. The content of the buffer outside
of the specified rect is NOT modified by this call.
It is legal for several different threads to lock a buffer for read
access; none of the threads are blocked.
Locking a buffer simultaneously for write or read/write is undefined,
but will neither terminate the process nor block the caller.
AHardwareBuffer_lock may return an error or leave the buffer's
content in an indeterminate state.
If the buffer has AHARDWAREBUFFER_FORMAT_BLOB, it is legal lock it
for reading and writing in multiple threads and/or processes
simultaneously, and the contents of the buffer behave like shared
memory.
\return 0 on success. -EINVAL if \a buffer is NUL, the usage flags
are not a combination of AHARDWAREBUFFER_USAGE_CPU_*, or the buffer
has more than one layer. Error number if the lock fails for any other
reason.
Lock the AHardwareBuffer for direct CPU access.
This function can lock the buffer for either reading or writing. It may block if the hardware needs to finish rendering, if CPU caches need to be synchronized, or possibly for other implementation- specific reasons.
The passed AHardwareBuffer must have one layer, otherwise the call will fail.
If \a fence is not negative, it specifies a fence file descriptor on which to wait before locking the buffer. If it's negative, the caller is responsible for ensuring that writes to the buffer have completed before calling this function. Using this parameter is more efficient than waiting on the fence and then calling this function.
The \a usage parameter may only specify AHARDWAREBUFFER_USAGE_CPU_*. If set, then outVirtualAddress is filled with the address of the buffer in virtual memory. The flags must also be compatible with usage flags specified at buffer creation: if a read flag is passed, the buffer must have been created with AHARDWAREBUFFER_USAGE_CPU_READ_RARELY or AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN. If a write flag is passed, it must have been created with AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY or AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN.
If \a rect is not NUL, the caller promises to modify only data in the area specified by rect. If rect is NUL, the caller may modify the contents of the entire buffer. The content of the buffer outside of the specified rect is NOT modified by this call.
It is legal for several different threads to lock a buffer for read access; none of the threads are blocked.
Locking a buffer simultaneously for write or read/write is undefined, but will neither terminate the process nor block the caller. AHardwareBuffer_lock may return an error or leave the buffer's content in an indeterminate state.
If the buffer has AHARDWAREBUFFER_FORMAT_BLOB, it is legal lock it for reading and writing in multiple threads and/or processes simultaneously, and the contents of the buffer behave like shared memory.
\return 0 on success. -EINVAL if \a buffer is NUL, the usage flags are not a combination of AHARDWAREBUFFER_USAGE_CPU_*, or the buffer has more than one layer. Error number if the lock fails for any other reason.